<?php
/**
 * 绵阳妇幼中间件
 *
 *
 * @author wangwh
 */

namespace PzhrsTest\Controller;

class PzhTestControlController
{
    // SoapClient 对象
    private $soap = FALSE;

    // 记录是否为正式环境
    private $isFormal = FALSE;

    //是否开启缓存
    private static $CACHE = false;

    // 医疗机构科室列表缓存建
    private static $CACHE_INSTITUTION_CLASS_LIST = 'CACHE_INSTITUTION_CLASS_LIST';


    static $URL_API = 'http://220.166.60.252:8083/wxjk.dll/wsdl/Iwxjk';//http://192.168.203.55:8078/HisService.asmx?WSDL
    static $back_URL_API = "http://localhost:8081/";

    //医院id
    private $hospitalId;

    //自助机id
    private $userId;

    /**
     * 构造函数
     */
    function __construct()
    {
        header('Content-Type: text/html; charset=utf-8');
        $this->hospitalId = 75;
        if (!method_exists($this, ACTION_NAME)) {
            $function = ACTION_NAME;
            A('Receive')->$function();
        }
    }

    public function xml_to_array($list){
        $ob= simplexml_load_string($list);
        $json  = json_encode($ob);
        $configData = json_decode($json, true);
        return $configData;
    }

    public $hospitalKey = array(
        "75" => "7daf7603429012aeae417fa9beed9c75",
    );
    //正式地址
    //	static $URL_API = "http://125.64.9.81:8088/rmc/mobile/web";
    //	static $version = "2.2.7";
    //	private $token = "6a2967e64a994e54b533aa7942328179";
    //正式地址


    // 	static $URL_API = "http://125.64.9.81:8088/rmc/mobile/web";
    /**
     * 请求His API
     *
     *   使用SoapClient请求HIS webservice接口
     *
     * @param String $Flag 类型
     * @param String $Content xml请求内容
     * @param String $Result_K 返回xml中的跟节点key
     *
     * @return array
     */


    private function soapGetDate($Flag, $Content)
    {
//        $this->isFormal = ($_SERVER['SERVER_NAME']!="localhost" && "histest.mobimedical.cn"!=$_SERVER['SERVER_NAME']);
        $this->isFormal = false;

        if (!$this->soap) {
            $this->soap = new \SoapClient(self::$URL_API, array("connection_timeout" => 15));
        }
        try {

            /* 正式环境 */
            if ($this->isFormal) {
                //专线接口,走平台
                try {
                    $result = $this->soap->Weixin($Content);
                } catch (\Exception $e) {
                    $fileContent = $Content . "\n" . $e->getMessage();
                    $dir = "soapGetDate/";
                    \Org\Util\File::createDir($dir);
                    file_put_contents($dir . $Flag . "_error.txt", $fileContent);
                    return array('ResultCode' => -1, "ErrorMsg" => "系统异常，请稍后重试21！");
                }
                $Result_K = "Weixin" . Result;

                /* 测试环境 */
            } else {
                $result = $this->soap->$Flag( $Content);
                /* 记录请求日志   */
                $fileContent = $Content . "\r" . var_export($result, true);
                $dir = "soapGetDate/" . date("Y-m-d") . "/" . $Flag . "/";
                $filename = date("H_i_s") . "_" . rand(10000, 99999);
                writeLog($dir, $filename, $fileContent);

                return json_decode(json_encode(json_decode(json_encode((array)simplexml_load_string(substr($result, 54)), true))), true);
            }


        } catch (\Exception $e) {
            /* 记录请求异常日志  */
            $fileContent = $Content . "\n" . $e->getMessage();
            $dir = "soapGetDate/" . date("Y-m-d") . "/" . $Flag . "/";
            $filename = date("H_i_s") . "_error";
            writeLog($dir, $filename, $fileContent);
            return array('ResultCode' => -1, "ErrorMsg" => "系统异常，请稍后重试22！");
            exit;
        }
    }


    function Post($url, $method, $post = null)
    {
        if (is_array($post)) {
            ksort($post);
            $content = http_build_query($post);
            $content_length = strlen($content);
            $options = array(
                'http' => array(
                    'method' => 'POST',
                    'header' =>
                        "Content-type: application/x-www-form-urlencoded; charset=utf-8\r\n" .
                        "Content-length: $content_length\r\n",
                    'content' => $content
                )
            );
            $res = file_get_contents($url, false, stream_context_create($options));
            $fileContent = var_export($post, true) . "\r" . var_export($res, true) . "\r" . var_export(json_decode($res, true), true);
            $dir = "soapGetDateXt/" . date("Y-m-d") . "/" . $method . "/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
            return $res;
        }
    }

    /**
     * 中间件签名验证
     * @param array $params
     * @return string
     */
    function middelEnCodeSign($params)
    {
        ksort($params);
        $preString = "";
        $time = $params['time'];
        $hospitalId = $params['hospitalId'];
        foreach ($params as $k => $v) {
            if ($k == 'time' || $k == 'sign' || !$v)
                continue;
            $preString .= $k . "=" . $v;
        }

        $keyString = $this->hospitalKey[$hospitalId];
        //加密
        return sha1($preString . $keyString . $time);
    }


    /**
     * 确认病人信息  绑卡
     * @param $car_no '就诊卡号'
     * @param $user_name '病人姓名'
     */
    public function cardInfoQuery()
    {
//        $sign       = $this->middelEnCodeSign($_POST);
//        if($sign!=$_POST['sign']){
//            echo "签名不正确";exit;
//        }
        $card_no    = $_POST['identy_id'];
        $user_name  = $_POST['user_name'];

        //$card_no = '600143066';

        $Content ="<HIS><card_no>".$card_no."</card_no></HIS>";

        $searchKey = "patient";
        $result = $this->soapGetDate($searchKey, $Content);
        if ($result['status'] == 0 && !empty($result['data']['name'])) {
            if ($result['data']['name'] == $user_name && $result['status'] == 0) {
                $returnArr['status'] = 1;
                $returnArr['errorMsg'] = "绑卡成功";
                $returnArr['data'] = $result['Data'];
            } else {
                $returnArr['status'] = 2;
                $returnArr['errorMsg'] = "姓名输入有误";
                $returnArr['data'] = array();
            }

        } else {
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $result['ResultMsg'];
            $returnArr['data'] = array();

        }

        echo json_encode($returnArr);
    }

    public function Test_jj()
    {
        //echo '122';die();
        //$client = new \SOAPClient('http://192.168.100.149:9192/OrderTreat/services/HosiptalManager?wsdl');
        $url='http://10.166.121.249:8089/xtpt/services/yinHaiBusiness?wsdl';
        $s=new \SoapClient($url);
        /*
         *SoapHeader参数说明如下所示:
         *'http://tempuri.org/'   namespace(命名空间可省略)
         *'MySoapHeader'          SoapHeader头的类名
         *'array(...)'            存放标识身份的字符串参数
         *'true'                  是否必须处理该header
        */
        $mmkj='http://yinhai.com';
        $code='yinhai@789'; //授权码
        $funNo='WX_001';    //交易编号 
        $xml_xx="<input><aac001>4000612523</aac001><startrow>1</startrow><endrow>3</endrow><inputxml><inputxml><aac002>510402198306076317</aac002><aac003>张帆</aac003></inputxml></inputxml></input>";
        $apiUrl='http://pzh.91cure.com/index.php?g=Home&m=Test&a=pzh_sign';
        $params1 = array();
        $params1['content']=$xml_xx;
        $xmlsing=$this->PostData_jm($apiUrl,$params1);

        $auth_header = array( "jybh" =>$funNo ,"systemKey" =>$code ,"source" =>$xml_xx,"signature" =>$xmlsing  );
        $authvalues = new \SoapVar($auth_header, SOAP_ENC_OBJECT,"system",$mmkj);  
        $u = new \SoapHeader($mmkj, 'system', $authvalues);
        $s->__setSoapHeaders($u);
        $params['inputxml']=$xml_xx;
        $suc=$s->callBusiness($params);
        $data=$suc->return;
        $tesres = $this->xml_to_array($data);
        dump($tesres);
    }
    //养老保险查询
    function EndowmentInsurance_Query(){
        $identyId='510402198306076317';   //身份证号码
        $name='张帆';       //姓名
        $funNo='WX_001';    //交易编号
        $xml="<input><aac001>4000612523</aac001><startrow>1</startrow><endrow>3</endrow><inputxml><inputxml><aac002>".$identyId."</aac002><aac003>".$name."</aac003></inputxml></inputxml></input>";
        $url='http://10.166.121.249:8089/xtpt/services/yinHaiBusiness?wsdl';
        $client=new \SoapClient($url);
        dump($xml);
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        $datares=$result_list['output']['row'];
        if($result_list['code']=='1'){
            $returnArr['status'] = 1;
            $returnArr['errorMsg']=$result_list['message'];
            $returnArr['data']['name']=$name;                   //姓名
            $returnArr['data']['identyId']=$identyId;           //身份证号码
            $returnArr['data']['insured_units']=$datares['aab004'];     //参保所在单位名称
            $returnArr['data']['insured_status']=$datares['aac008'];    //参保状态
            $returnArr['data']['payment_status']=$datares['aac031'];    //缴费状态
            $returnArr['data']['payment_max_period']=$datares['aae002'];    //最大缴费期号
            $returnArr['data']['payment_total_local']=$datares['aic027'];   //在本地缴费总金额
            $returnArr['data']['payment_total_monthly']=$datares['aic079']; //累计缴费总月数
            $returnArr['data']['payment_total_money']=$datares['aic040'];   //截至当前个人账户累计存储额         
            //echo json_encode($returnArr);exit;
        }else{//格式化为标准接口模式
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $result_list['message'];
        };
        dump($returnArr);
    }

    /**
     * 统一调接口方法 
     * $xml       接口传递的参数
     * $funNo     接口的方法名
     * $client    接口需要调用的webservice对象 
     * */
    function Get_service_api($xml,$funNo,$client){
        $mmkj='http://yinhai.com';
        $code='wx20170921'; //授权码
        //$apiUrl='http://pzh.91cure.com/index.php?g=Home&m=Test&a=pzh_sign';
        $apiUrl='http://127.0.0.1:442/index.php?g=Whszxyy&m=WhszxyyControlxin1&a=pzh_sign';
        $params1 = array();
        $params1['content']=$xml;
        $xmlsing=$this->PostData_jm($apiUrl,$params1);
        $auth_header = array( "jybh" =>$funNo ,"systemKey" =>$code ,"source" =>$xml,"signature" =>$xmlsing  );
        $authvalues = new \SoapVar($auth_header, SOAP_ENC_OBJECT,"system",$mmkj);  
        $u = new \SoapHeader($mmkj, 'system', $authvalues);
        $client->__setSoapHeaders($u);
        $params['inputxml']=$xml;
        $suc=$client->callBusiness($params);
        $data=$suc->return;
        $tesres = $this->xml_to_array($data);
        return  $tesres;
    }
    /**
     * 数字签名
     * $url         签名地址
     * $post        签名参数
     * */
    function PostData_jm($url, $post = null) {
        if (is_array($post)) {
            ksort($post);
            $rsaPrivateKeyPem='http://172.16.8.2:442/bcp.keystore';
            $content11 = htmlspecialchars_decode($post['content']);
            $priKey = file_get_contents($rsaPrivateKeyPem);  
            $res1 = openssl_pkey_get_private($priKey);
            openssl_sign($content11, $sign, $res1);
            openssl_free_key($res1);   
            $sign = bin2hex($sign);
            return $sign;
            //return $res;
        }
    }


    /**
     * 科室信息
     * @param 
     */
    function GetDept(){
        $hospitalCode='525009'; //医院编码
        $deptCode='';       //科室编号
        $funNo='HIS001';    //交易编号
        //dump(C('URL_API'));die();
        $xml="<input><Request><deptcode>".$deptCode."</deptcode><functionid>".$funNo."</functionid><akb020>".$hospitalCode."</akb020></Request></input>";
        dump($xml);//die();

        $client=new \SoapClient(C('URL_API'));
        //$client='http://10.166.121.249:8089/xtpt/services/yinHaiBusiness?wsdl';
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        dump($result_list);die();

        if($this->is_idcard($identyId))
        {
            $client=new \SoapClient(C('URL_API'));
            $result_list=$this->Get_service_api($xml,$funNo,$client);
            dump($result_list);
            if($result_list['code']=='1'){
                $returnArr['status'] = 1;
                $returnArr['errorMsg']=$result_list['message'];       
                //echo json_encode($returnArr);exit;
            }else{//格式化为标准接口模式
                $returnArr['status'] = 2;
                $returnArr['errorMsg'] = $result_list['message'];
            };
        } else {
            echo 'sfz不合法!';
            $returnArr['status'] = 3;
            $returnArr['errorMsg'] = '身份证号码输入不正确，请输入正确的身份证号码！';
        };//die();
        dump($returnArr);
        /* 记录请求日志   */
            $fileContent = var_export(json_encode($returnArr), true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetTiedCard_Regtt/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        echo json_encode($returnArr);
    }

    /**
     * 社保卡绑定与解绑
     * @param 
     */
    function GetTiedCard_Reg(){
        $identyId='510402198306076317';   //身份证号码
        $name='张帆';       //姓名
        $wx_openid='tcyl_222';      //第三方ID ‘tcyl_’加微信openid
        $phone='13127530852';          //电话2223988  13550908933
        $Card_no='D11718733x';        //社保卡卡号 D13825348 4000611622  D04016899
        $Trading_channels='01';   //交易渠道 渠道目前只有微信,请默认写01
        $Transaction_Type='2';   //交易类型 1-绑定,2-解绑
        $funNo='WX_010';    //交易编号
        //dump(C('URL_API'));die();
        $xml="<input><inputxml><inputxml><yad901>".$wx_openid."</yad901><aac002>".$identyId."</aac002><aac003>".$name."</aac003><aae005>".$phone."</aae005><akc020>".$Card_no."</akc020><yad961>".$Trading_channels."</yad961><yad941>".$Transaction_Type."</yad941></inputxml></inputxml></input>";
        dump($xml);//die();
        if($this->is_idcard($identyId))
        {
            $client=new \SoapClient(C('URL_API'));
            $result_list=$this->Get_service_api($xml,$funNo,$client);
            dump($result_list);
            if($result_list['code']=='1'){
                $returnArr['status'] = 1;
                $returnArr['errorMsg']=$result_list['message'];       
                //echo json_encode($returnArr);exit;
            }else{//格式化为标准接口模式
                $returnArr['status'] = 2;
                $returnArr['errorMsg'] = $result_list['message'];
            };
        } else {
            echo 'sfz不合法!';
            $returnArr['status'] = 3;
            $returnArr['errorMsg'] = '身份证号码输入不正确，请输入正确的身份证号码！';
        };//die();
        dump($returnArr);
        /* 记录请求日志   */
            $fileContent = var_export(json_encode($returnArr), true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetTiedCard_Regtt/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        echo json_encode($returnArr);
    }

    /**
     * 养老保险缴费信息查询
     * @param 
     */
    function GetPensionPayment_Inquire(){
        $wx_openid='tcyl_ohNH9sgZMMsP6MFSG5mrbrQXnYk4'; //第三方ID tcyl_oeTsDv8zEhse5Hs_isEog1ncAlQ8
        $funNo='WX_001';    //交易编号
        $xml="<input><inputxml><inputxml><yad901>".$wx_openid."</yad901></inputxml></inputxml></input>";
        dump($xml);
        $client=new \SoapClient(C('URL_API'));
        echo C('URL_API');die();
        $result_list=$this->Get_service_api($xml,$funNo,$client);

        dump($result_list);
        $datares=$result_list['output']['row'];
        if(is_array($result_list['message'])){
            $llmessage='';  
        }else{
            $llmessage=$result_list['message']; 
        };

        if($result_list['code']=='1'){
            $returnArr['status'] = 1;
            $returnArr['errorMsg']=$llmessage;    
            $returnArr['data']['insured_units']=$datares['aab004'];     //所在单位
            $returnArr['data']['insured_status']=$datares['aac008'];    //参保状态
            $returnArr['data']['payment_status']=$datares['aac031'];    //缴费状态
            $returnArr['data']['CurrentPayment_base']=$datares['aic010'];    //当前缴费基数
            $returnArr['data']['payment_max_period']=$datares['aae002'];    //缴费期号(月份)
            $returnArr['data']['payment_total_local']=$datares['aic027'];   //在本地缴费总金额
            $returnArr['data']['payment_total_monthly']=$datares['aic079']; //实际缴费月数（不含视同缴费年限）
            $returnArr['data']['payment_total_money']=$datares['aic040'];   //个人账户存储额
            $returnArr['data']['InsuranceType']=$datares['aae140'];   //险种类型      
        }else{//格式化为标准接口模式
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $llmessage;
        };
        dump($returnArr);
        echo json_encode($returnArr);
    }

    /**
     * 养老保险退休信息查询
     * @param 
     */
    function GetPensionRetirement_Inquire(){
        $wx_openid='tcyl_ohNH9sgZMMsP6MFSG5mrbrQXnYk4'; //第三方ID
        $funNo='WX_002';    //交易编号
        $xml="<input><inputxml><inputxml><yad901>".$wx_openid."</yad901></inputxml></inputxml></input>";
        dump($xml);
        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        dump($result_list);
        $datares=$result_list['output']['row'];
        if($result_list['code']=='1'){
            $returnArr['status'] = 1;
            $returnArr['errorMsg']=$result_list['message'];    
            $returnArr['data']['treatment_units']=$datares['aae116'];     //待遇发放状态
            $returnArr['data']['payment_max_period']=$datares['aae002'];    //最大领取期号
            $returnArr['data']['pensiontreatment']=$datares['aic142'];    //当前养老待遇金额    
        }else{//格式化为标准接口模式
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $result_list['message'];
        };
        dump($returnArr);
        echo json_encode($returnArr);
    }

    /**
     * 医疗保险缴费信息查询
     * @param 
     */
    function GetMedicalInsurance_Inquire(){
        $wx_openid='tcyl_oeTsDv8zEhse5Hs_isEog1ncAlQ8'; //第三方ID
        $funNo='WX_003';    //交易编号
        $xml="<input><inputxml><inputxml><yad901>".$wx_openid."</yad901></inputxml></inputxml></input>";
        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        $datares=$result_list['output']['row'];
        if($result_list['code']=='1'){
            $returnArr['status'] = 1;
            $returnArr['errorMsg']=$result_list['message'];     
            $returnArr['data']['insured_units']=$datares['aab004'];     //参保所在单位
            $returnArr['data']['insured_status']=$datares['aac008'];    //参保状态
            $returnArr['data']['payment_status']=$datares['aac031'];    //缴费状态
            $returnArr['data']['payment_max_period']=$datares['aae002'];    //缴费最大期号
            $returnArr['data']['payment_total_money']=$datares['aic040'];   //个人账户余额      
        }else{//格式化为标准接口模式
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $result_list['message'];
        };
        dump($returnArr);
        echo json_encode($returnArr);
    }

    /**
     * 职工医疗保险缴费信息查询
     * @param 
     */
    function GetMedicalInsuranceZG_Inquire(){
        $tcylkey = C('TCYL_KEY');
        //$wx_openid  = $tcylkey.$_POST['wx_openid'];
        $wx_openid='tcyl_ohNH9sgZMMsP6MFSG5mrbrQXnYk4'; //第三方ID
        $funNo='WX_003_ZG';    //交易编号
        $xml="<input><inputxml><inputxml><yad901>".$wx_openid."</yad901></inputxml></inputxml></input>";
        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        dump($result_list);
        $datares=$result_list['output']['row'];
        if(is_array($result_list['message'])){
            $llmessage='';  
        }else{
            $llmessage=$result_list['message']; 
        };
        if($result_list['code']=='1'){
            $returnArr['status'] = 1;
            $returnArr['errorMsg']=$llmessage;     
            $returnArr['data']['insured_units']=$datares['aab004'];     //所在单位
            $returnArr['data']['insured_status']=$datares['aac008'];    //参保状态
            $returnArr['data']['payment_status']=$datares['aac031'];    //缴费状态
            $returnArr['data']['payment_max_period']=$datares['aae002'];    //缴费最大期
            $returnArr['data']['payment_total_money']=$datares['aic040'];   //个人账户余额
            $returnArr['data']['CurrentPayment_base']=$datares['aic010'];   //当前缴费基数
            $returnArr['data']['InsuranceType']=$datares['aae140'];   //险种类型       
        }else{//格式化为标准接口模式
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $llmessage;
        };
        dump($returnArr);
        echo json_encode($returnArr);
    }

    /**
     * 居民医疗保险缴费信息查询
     * @param 
     */
    function GetMedicalInsuranceJM_Inquire(){
        $tcylkey = C('TCYL_KEY');
        //$wx_openid  = $tcylkey.$_POST['wx_openid'];
        $wx_openid='tcyl_ohNH9srnIRX_juYX17FzamqbswLo'; //第三方ID
        $funNo='WX_003_JM';    //交易编号
        $xml="<input><inputxml><inputxml><yad901>".$wx_openid."</yad901></inputxml></inputxml></input>";
        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        dump($result_list);
        $datares=$result_list['output']['row'];
        if(is_array($result_list['message'])){
            $llmessage='';  
        }else{
            $llmessage=$result_list['message']; 
        };
        if($result_list['code']=='1'){
            $returnArr['status'] = 1;
            $returnArr['errorMsg']=$llmessage;     
            $returnArr['data']['insured_units']=$datares['aab004'];     //所在单位
            $returnArr['data']['insured_status']=$datares['aac008'];    //参保状态
            $returnArr['data']['payment_status']=$datares['aac031'];    //缴费状态
            $returnArr['data']['payment_max_period']=$datares['aae002'];    //缴费最大期
            $returnArr['data']['payment_total_money']=$datares['aic040'];   //个人账户余额
            $returnArr['data']['CurrentPayment_base']=$datares['aic010'];   //当前缴费基数
            $returnArr['data']['InsuranceType']=$datares['aae140'];   //险种类型       
        }else{//格式化为标准接口模式
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $llmessage;
        };
        dump($returnArr);
        echo json_encode($returnArr);
    }

    /**
     * 工伤保险缴费信息查询
     * @param 
     */
    function GetInjuryInsurance_Inquire(){
        $wx_openid='tcyl_ohNH9srnIRX_juYX17FzamqbswLo'; //第三方ID
        $funNo='WX_004';    //交易编号
        $xml="<input><inputxml><inputxml><yad901>".$wx_openid."</yad901></inputxml></inputxml></input>";
        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        dump($result_list);
        $datares=$result_list['output']['row'];
        if($result_list['code']=='1'){
            $returnArr['status'] = 1;
            $returnArr['errorMsg']=$result_list['message'];     
            $returnArr['data']['insured_units']=$datares['aab004'];     //所在单位
            $returnArr['data']['insured_status']=$datares['aac008'];    //参保状态
            $returnArr['data']['payment_status']=$datares['aac031'];    //缴费状态
            $returnArr['data']['payment_max_period']=$datares['aae002'];    //缴费最大期
            $returnArr['data']['payment_total_money']=$datares['aic027'];   //缴费总金额
            $returnArr['data']['CurrentPayment_base']=$datares['aic010'];   //当前缴费基数
            $returnArr['data']['InsuranceType']=$datares['aae140'];   //险种类型 
        }else{//格式化为标准接口模式
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $result_list['message'];
        };
        dump($returnArr);
        echo json_encode($returnArr);
    }

    /**
     * 生育保险缴费信息查询
     * @param 
     */
    function GetMaternityInsurance_Inquire(){
        $wx_openid='tcyl_oeTsDvx_c9sJhQ3XrqxBeVsfDJxY'; //第三方ID
        $funNo='WX_005';    //交易编号
        $xml="<input><inputxml><inputxml><yad901>".$wx_openid."</yad901></inputxml></inputxml></input>";
        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        dump($result_list);
        $datares=$result_list['output']['row'];
        if($result_list['code']=='1'){
            $returnArr['status'] = 1;
            $returnArr['errorMsg']=$result_list['message'];     
            $returnArr['data']['insured_units']=$datares['aab004'];     //所在单位
            $returnArr['data']['insured_status']=$datares['aac008'];    //参保状态
            $returnArr['data']['payment_status']=$datares['aac031'];    //缴费状态
            $returnArr['data']['payment_max_period']=$datares['aae002'];    //缴费最大期
            $returnArr['data']['payment_total_money']=$datares['aic010'];   //缴费总金额
            $returnArr['data']['CurrentPayment_base']=$datares['aic010'];   //当前缴费基数
            $returnArr['data']['InsuranceType']=$datares['aae140'];   //险种类型 
        }else{//格式化为标准接口模式
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $result_list['message'];
        };
        dump($returnArr);
        echo json_encode($returnArr);
    }

    /**
     * 失业保险缴费信息查询
     * @param 
     */
    function GetUnemploymentInsurance_Inquire(){
        $wx_openid='tcyl_oeTsDv8zEhse5Hs_isEog1ncAlQ8'; //第三方ID
        $funNo='WX_006';    //交易编号
        $xml="<input><inputxml><inputxml><yad901>".$wx_openid."</yad901></inputxml></inputxml></input>";
        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        $datares=$result_list['output']['row'];
        if($result_list['code']=='1'){
            $returnArr['status'] = 1;
            $returnArr['errorMsg']=$result_list['message'];     
            $returnArr['data']['insured_units']=$datares['aab004'];     //参保所在单位
            $returnArr['data']['insured_status']=$datares['aac008'];    //参保状态
            $returnArr['data']['payment_status']=$datares['aac031'];    //缴费状态
            $returnArr['data']['payment_max_period']=$datares['aae002'];    //缴费最大期号
            $returnArr['data']['payment_total_money']=$datares['aic027'];   //缴费总金额
        }else{//格式化为标准接口模式
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $result_list['message'];
        };
        dump($returnArr);
        echo json_encode($returnArr);
    }

    /**
     * 失业保险待遇信息查询
     * @param 
     */
    function GetUnemploymentTreatment_Inquire(){
        $wx_openid='tcyl_oeTsDv8zEhse5Hs_isEog1ncAlQ8'; //第三方ID
        $funNo='WX_007';    //交易编号
        $xml="<input><inputxml><inputxml><yad901>".$wx_openid."</yad901></inputxml></inputxml></input>";
        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        //dump($result_list);
        $datares=$result_list['output']['row'];
        if($result_list['code']=='1'){
            $returnArr['status'] = 1;
            $returnArr['errorMsg']=$result_list['message'];     
            $returnArr['data']['Unemployment_time']=$datares['ajc090'];     //本次失业时间
            $returnArr['data']['ShouldEnjoy_Months']=$datares['ajc097'];    //应享受月数
            $returnArr['data']['HasEnjoy_Months']=$datares['ajc098'];       //已享受月数
            $returnArr['data']['RemainingEnjoy_Months']=$datares['ajc099'];    //剩余享受月数
            $returnArr['data']['TreatmentEnjoyStart']=$datares['ajc100'];   //待遇享受开始年月
            $returnArr['data']['TreatmentEnjoyEnd']=$datares['ajc106'];     //待遇享受终止年月 
            $returnArr['data']['CurrentTreatment_amount']=$datares['ajc140'];     //当前待遇金额
        }else{//格式化为标准接口模式
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $result_list['message'];
        };
        dump($returnArr);
        echo json_encode($returnArr);
    }

    /**
     * 社会保障卡信息查询
     * @param 
     */
    function GetSocialSecurityCard_Inquire(){
        $wx_openid='tcyl_oeTsDv8zEhse5Hs_isEog1ncAlQ8'; //第三方ID
        $funNo='WX_008';    //交易编号
        $xml="<input><inputxml><inputxml><yad901>".$wx_openid."</yad901></inputxml></inputxml></input>";
        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        //dump($result_list);
        $datares=$result_list['output']['row'];
        if($result_list['code']=='1'){
            $returnArr['status'] = 1;
            $returnArr['errorMsg']=$result_list['message'];     
            $returnArr['data']['SSCard_no']=$datares['akc020'];     //社会保障卡卡号
            $returnArr['data']['Bank']=$datares['aae008'];          //所属银行
            $returnArr['data']['BankAccount']=$datares['aae010'];   //银行帐号
        }else{//格式化为标准接口模式
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $result_list['message'];
        };
        dump($returnArr);
        echo json_encode($returnArr);
    }

    /**
     * 医保账户支出明细查询
     * @param 
     */
    function GetMedicalAccountExpenditure_Details(){
        $wx_openid='tcyl_oeTsDvx_c9sJhQ3XrqxBeVsfDJxY'; //第三方ID oeTsDvwWqOmEwlDtlgehMRTqOX0A
        //$IncomeExp_Type='2';    //收支类型 1收入,2支出
        $StartData='1';    //开始行
        $EndData='10';      //结束行
        $funNo='WX_009';    //交易编号
        $xml="<input><inputxml><inputxml><yad901>".$wx_openid."</yad901><aae030>".$StartData."</aae030><aae031>".$EndData."</aae031></inputxml></inputxml></input>";
        dump($xml);
        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        dump($result_list);

        $te_arry=$result_list['output']['row']['ykc105'];
        $ywsz_jj=$result_list['output']['row'];
        if(is_array($result_list['message'])){
            $llmessage='';  
        }else{
            $llmessage=$result_list['message']; 
        }; 
        //$datares=$result_list['output']['row'];
        if($result_list['code']=='1'){
            $returnArr['status'] = 1;
            $returnArr['errorMsg']=$llmessage;   
            if($te_arry){
                $returnArr['data'][0]['Spending_Time']=$ywsz_jj['ykc105'];  //消费时间
                $returnArr['data'][0]['Total_Amount']=$ywsz_jj['yka100'];   //总金额
                $returnArr['data'][0]['Spending_Type']=$ywsz_jj['row']['aka130'];//消费类型
                $returnArr['data'][0]['PersonalAccount_Payment']=$ywsz_jj['row']['yka136'];//个人账户支付
                $returnArr['data'][0]['Cash_Payment']=$ywsz_jj['row']['yka137'];   //现金支付
                $returnArr['data'][0]['Reimbursement_Amount']=$ywsz_jj['row']['ykh011'];   //报销金额
                $returnArr['data'][0]['Consumption_Place']=$ywsz_jj['row']['akb021'];   //消费地点
            } else { 
                foreach ($ywsz_jj as $k => $v) {
                    $returnArr['data'][$k]['Spending_Time']=$ywsz_jj[$k]['ykc105'];  //消费时间
                    $returnArr['data'][$k]['Total_Amount']=$ywsz_jj[$k]['yka100'];   //总金额
                    $returnArr['data'][$k]['Spending_Type']=$ywsz_jj[$k]['row']['aka130'];//消费类型
                    $returnArr['data'][$k]['PersonalAccount_Payment']=$ywsz_jj[$k]['row']['yka136'];//个人账户支付
                    $returnArr['data'][$k]['Cash_Payment']=$ywsz_jj[$k]['row']['yka137'];   //现金支付
                    $returnArr['data'][$k]['Reimbursement_Amount']=$ywsz_jj[$k]['row']['ykh011'];   //报销金额
                    $returnArr['data'][$k]['Consumption_Place']=$ywsz_jj[$k]['row']['akb021'];   //消费地点
                }
            }
        }else{//格式化为标准接口模式
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $llmessage;
        };
        dump($returnArr);
        echo json_encode($returnArr);
    }

    /**
     * 参保人缴费明细信息查询
     * @param 
     */
    function GetPayment_Details(){
        $tcylkey = C('TCYL_KEY');
        $wx_openid  = 'tcyl_ohNH9srnIRX_juYX17FzamqbswLo';
        $Insurance_Type = '1';    //险种类型 
        $StartIssue = '200401';  //开始期号
        $EndIssue = '201712';    //结束期号
        //$wx_openid='tcyl_oeTsDv8zEhse5Hs_isEog1ncAlQ8'; //第三方ID
        $funNo='WX_011';    //交易编号
        $xml="<input><inputxml><inputxml><yad901>".$wx_openid."</yad901><aae140>".$Insurance_Type."</aae140><aae030>".$StartIssue."</aae030><aae031>".$EndIssue."</aae031></inputxml></inputxml></input>";
        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        dump($result_list);//die();
        $te_arry=$result_list['output']['row']['aae002'];
        $ywsz_jj=$result_list['output']['row']; 
        if(is_array($result_list['message'])){
            $llmessage='';  
        }else{
            $llmessage=$result_list['message']; 
        };
        //$datares=$result_list['output']['row'];
        if($result_list['code']=='1'){
            $returnArr['status'] = 1;
            $returnArr['errorMsg']=$llmessage;   
            if($te_arry){
                $returnArr['data'][0]['Insured_units']=$ywsz_jj['aab004'];//单位
                $returnArr['data'][0]['Payment_Issue']=$ywsz_jj['aae002'];//费款所属期
                $returnArr['data'][0]['Pay_Base']=$ywsz_jj['aac400'];   //缴费基数
                $returnArr['data'][0]['Payment_Amount']=$ywsz_jj['aab250'];    //个人缴费金额
                $returnArr['data'][0]['UnitPersonal_amount']=$ywsz_jj['aab251'];//单位缴费划入个人账户金额
                $returnArr['data'][0]['UnitCoordinate_amount']=$ywsz_jj['aab252'];//单位缴费划入统筹账户金额
                $returnArr['data'][0]['Interest_amount']=$ywsz_jj['aab262'];    //利息
                $returnArr['data'][0]['Late_fee']=$ywsz_jj['aab262'];       //滞纳金
            } else { 
                foreach ($ywsz_jj as $k => $v) {
                    $returnArr['data'][$k]['Insured_units']=$ywsz_jj[$k]['aab004'];//单位
                    $returnArr['data'][$k]['Payment_Issue']=$ywsz_jj[$k]['aae002'];//费款所属期
                    $returnArr['data'][$k]['Pay_Base']=$ywsz_jj[$k]['aac400'];   //缴费基数
                    $returnArr['data'][$k]['Payment_Amount']=$ywsz_jj[$k]['aab250'];    //个人缴费金额
                    $returnArr['data'][$k]['UnitPersonal_amount']=$ywsz_jj[$k]['aab251'];//单位缴费划入个人账户金额
                    $returnArr['data'][$k]['UnitCoordinate_amount']=$ywsz_jj[$k]['aab252'];//单位缴费划入统筹账户金额
                    $returnArr['data'][$k]['Interest_amount']=$ywsz_jj[$k]['aab262'];    //利息
                    $returnArr['data'][$k]['Late_fee']=$ywsz_jj[$k]['aab262'];       //滞纳金
                }
            }
        }else{//格式化为标准接口模式
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $llmessage;
        };
        dump($returnArr);
        echo json_encode($returnArr);
    }

    /**
     * 医保查询信息(注册之前查询社保卡信息)
     * @param 
     */
    function GetShebaoChaxun(){
        $user_card_type = '1';    //证件类型
        $user_card_no = '429006198702040914';      //证件号码
        $user_name = '王新波';         //姓名
        $mi_card_no = 'D02453382';        //医保卡号
        $channel = '01';       //渠道 01 微信
        $bank_card_no = '';      //银行卡号
        $extend_params = '';     //扩展参数


        /*$user_card_type  = $_POST['user_card_type'];
        $user_card_no  = $_POST['user_card_no'];
        $user_name  = $_POST['user_name'];
        $mi_card_no  = $_POST['mi_card_no'];
        $bank_card_no  = $_POST['bank_card_no'];
        $extend_params  = $_POST['extend_params'];*/

        $funNo='WX_013';    //交易编号
        $xml="<input><inputxml><inputxml><aac002>".$user_card_no."</aac002><aac009>".$user_card_type."</aac009><aac003>".$user_name."</aac003><akc020>".$mi_card_no."</akc020><yad961>".$channel."</yad961><aae010>".$bank_card_no."</aae010><aae013>".$extend_params."</aae013></inputxml></inputxml></input>";
        dump($xml);
        if(strlen($mi_card_no)>10)
        {
            //echo '社保卡号长度不能超过10位！';
            $returnArr['status'] = 3;
            $returnArr['errorMsg'] = '社保卡号长度不能超过10位！';
        } else {
            if($user_card_type != '1')
            {
                $returnArr['status'] = 3;
                $returnArr['errorMsg'] = '证件类型输入的错误，身份证类型为1！';
            } else {
                if($this->is_idcard($user_card_no))
                {
                    //echo 'sfz合法!';
                    $client=new \SoapClient(C('URL_API'));
                    $result_list=$this->Get_service_api($xml,$funNo,$client);
                    dump($result_list);
                    if(is_array($result_list['message'])){
                        $llmessage='';  
                    }else{
                        $llmessage=$result_list['message']; 
                    };
                    $datares=$result_list['output'];

                    if(($result_list['code']=='1')&&($result_list['output']['akc141']=='INACTIVE')){
                        $returnArr['status'] = 3;
                        $returnArr['errorMsg'] = '卡信息没有找到！';
                    } else if(($result_list['code']=='1')&&($result_list['output']['akc141']=='ACTIVE')){
                        $returnArr['status'] = 1;
                        $returnArr['errorMsg']=$llmessage;     
                        $returnArr['data']['mi_card_no']=$mi_card_no;     //医保卡号
                        $returnArr['data']['mi_card_status']=$datares['akc141']; //医保卡状态  有效:ACTIVE  无效:INACTIVE
                        $returnArr['data']['user_card_type']=$datares['aac009'];   //证件类型
                        $returnArr['data']['user_card_no']=$datares['aac002'];       //证件号码
                        $returnArr['data']['user_name']=$datares['aac003'];             //姓名
                        $returnArr['data']['bank_card_no']=$datares['aae010'];      //银行卡号
                        $returnArr['data']['sbkbdzt']=$datares['sbkbdzt'];      //医保卡绑卡状态 0未绑卡，1绑卡
                        $returnArr['data']['wx_openid']=substr($datares['yad901'],5,strlen($datares['yad901'])-5);      //第三方ID
                        $returnArr['data']['mi_card_id']='';        //医疗证号
                        $returnArr['data']['mi_type']='';           //参保类型
                        $returnArr['data']['social_card_no']='';    //社会保障号
                        $returnArr['data']['mi_comp_no']='';        //电脑号

                        if(is_array($datares['aae010'])){
                            $returnArr['data']['bank_card_no']='';  
                        }else{
                            $returnArr['data']['bank_card_no']=$datares['aae010']; 
                        };
                    }else{//格式化为标准接口模式
                        $returnArr['status'] = 2;
                        $returnArr['errorMsg'] = $llmessage;
                    };
                } else {
                    //echo 'sfz不合法!';
                    $returnArr['status'] = 3;
                    $returnArr['errorMsg'] = '身份证号码输入不正确，请输入正确的身份证号码！';
                };//die();
            };
        };
        dump($returnArr);
        echo json_encode($returnArr);
    }

    /**
     * 制卡查询
     * @param 
     */
    function GetCard_Inquiries(){
        $tcylkey = C('TCYL_KEY');
        //$wx_openid  = $tcylkey.$_POST['wx_openid'];
        $wx_openid='tcyl_oeTsDv8zEhse5Hs_isEog1ncAlQ8'; //第三方ID
        $identyId='510402198306076317';    //社会保障号(身份证号码)
        $name='张帆';     //姓名
        $funNo='WZ2000';    //交易编号
        $xml="<input><inputxml><inputxml><yad901>".$wx_openid."</yad901><aac002>".$identyId."</aac002><aac003>".$name."</aac003><fwid>".$funNo."</fwid></inputxml></inputxml></input>";
        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        dump($xml);
        dump($result_list);
        $datares=$result_list['outputxml'];
        if(is_array($result_list['message'])){
            $llmessage='';  
        }else{
            $llmessage=$result_list['message']; 
        };
        if($result_list['code']=='1'){
            $returnArr['status'] = 1;
            $returnArr['errorMsg']=$llmessage;  
            $returnArr['data']['identyId']=$datares['aac002'];  //社会保障号
            $returnArr['data']['name']=$datares['aac003'];      //姓名
            $returnArr['data']['zkzt']=$datares['zkzt'];        //制卡状态
            $returnArr['data']['szztdate']=$datares['aae036'];  //所在状态时间        
            $returnArr['data']['cardno']=$datares['aaz501'];    //社保卡号
            $returnArr['data']['zkbank']=$datares['aae008'];    //制卡银行          
            $returnArr['data']['zkzbank']=$datares['aff002'];   //制卡支行
            $returnArr['data']['sbkszdq']=$datares['yae735'];   //社保卡所在地区
        }else{//格式化为标准接口模式
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $llmessage;
        };
        dump($returnArr);
        echo json_encode($returnArr);
    }

    /**
     * 职工医保个人账户收支查询
     * @param 
     */
    function GetPersonalIncome_Expenditure(){
        $tcylkey = C('TCYL_KEY');
        $wx_openid  = 'tcyl_ohNH9srnIRX_juYX17FzamqbswLo';
        $IncomeExpenditure_Type = '1';    //收支类型  1收入,2支出
        $StartData = '1';  //开始行
        $EndData = '10';    //结束行
        //$wx_openid='tcyl_oeTsDv8zEhse5Hs_isEog1ncAlQ8'; //第三方ID
        $funNo='WX_015';    //交易编号
        $xml="<input><inputxml><inputxml><yad901>".$wx_openid."</yad901><yad904>".$IncomeExpenditure_Type."</yad904><aae030>".$StartData."</aae030><aae031>".$EndData."</aae031></inputxml></inputxml></input>";
        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        $te_arry=$result_list['output']['row']['ykc028'];
        $ywsz_jj=$result_list['output']['row']; 
        if(is_array($result_list['message'])){
            $llmessage='';  
        }else{
            $llmessage=$result_list['message']; 
        };
        if($result_list['code']=='1'){
            $returnArr['status'] = 1;
            $returnArr['errorMsg']=$llmessage;   
            if($te_arry){
                $returnArr['data'][0]['IncomeExpenditure_Type']=$ywsz_jj['ykc028'];//收支类别
                $returnArr['data'][0]['IncomeExpenditure_Amount']=$ywsz_jj['ykc141'];//收支金额
                $returnArr['data'][0]['IncomeExpenditure_Date']=$ywsz_jj['ykc142'];   //收支时间
                $returnArr['data'][0]['Beizhu']=$ywsz_jj['aae013'];    //备注
                $returnArr['data'][0]['Medical_Institutions']=$ywsz_jj['akb021'];//就诊两定机构
                if ($ywsz_jj['aae013'] == 'null'){
                    $returnArr['data'][0]['Beizhu']='';    //备注
                };
                if ($ywsz_jj['akb021'] == 'null'){
                    $returnArr['data'][0]['Medical_Institutions']='';    //就诊两定机构
                };
            } else { 
                foreach ($ywsz_jj as $k => $v) {
                    //$returnArr['data'][$k]['Insured_units']=$ywsz_jj[$k]['aab004'];//单位
                    $returnArr['data'][$k]['IncomeExpenditure_Type']=$ywsz_jj[$k]['ykc028'];//收支类别
                    $returnArr['data'][$k]['IncomeExpenditure_Amount']=$ywsz_jj[$k]['ykc141'];//收支金额
                    $returnArr['data'][$k]['IncomeExpenditure_Date']=$ywsz_jj[$k]['ykc142'];   //收支时间
                    $returnArr['data'][$k]['Beizhu']=$ywsz_jj[$k]['aae013'];    //备注
                    $returnArr['data'][$k]['Medical_Institutions']=$ywsz_jj[$k]['akb021'];//就诊两定机构
                    if ($ywsz_jj[$k]['aae013'] == 'null'){
                        $returnArr['data'][$k]['Beizhu']='';    //备注
                    };
                    if ($ywsz_jj[$k]['akb021'] == 'null'){
                        $returnArr['data'][$k]['Medical_Institutions']='';    //就诊两定机构
                    };
                }
            }
        }else{//格式化为标准接口模式
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $llmessage;
        };
        dump($returnArr);
        echo json_encode($returnArr);
    }

    /**
     * 医保预结算
     * @param 
     */
    function GetPreSettlement(){
        $tcylkey = C('TCYL_KEY');

        $hospital_org_id='525009'; //医院编码
        $channel_id='1';      //渠道号 1 微信 2 支付宝 3.银联
        $pay_type='1';        //结算类型 1为挂号2为门诊
        $user_id=$tcylkey.'ohNH9spztdajN8bGok-hJjcfrZAk';      //第三方ID
        $social_card_no='D1516917X';  //社保卡号
        $user_card_no='510402198308010012'; //身份证
        $user_name='李建辉';    //姓名
        $ssp_order_id='TC2017122203';   //平台id
        $order_no='gh|178632';    //医院订单号
        $total_amount='15.00';  //医保总金额

        /*$hospital_org_id  = $_POST['hospital_org_id'];    //医院编码
        $channel_id  = $_POST['channel_id'];    //渠道号 1 微信 2 支付宝 3.银联
        $pay_type  = $_POST['pay_type'];        //结算类型 1为挂号2为门诊
        $user_id  = $tcylkey.$_POST['user_id'];      //第三方ID
        $social_card_no  = $_POST['social_card_no'];    //社保卡号
        $user_card_no  = $_POST['user_card_no'];        //身份证
        $user_name  = $_POST['user_name'];          //姓名
        $ssp_order_id  = $_POST['ssp_order_id'];    //平台id
        $order_no  = $_POST['order_no'];            //医院订单号
        $total_amount  = $_POST['total_amount'];    //医保总金额*/

        $funNo='HIS016';    //交易编号
        //dump(C('URL_API'));die();
        $xml="<input><inputxml><inputxml><hospital_org_id>".$hospital_org_id."</hospital_org_id><channel_id>".$channel_id."</channel_id><pay_type>".$pay_type."</pay_type><user><user_id>".$user_id."</user_id><social_card_no>".$social_card_no."</social_card_no><user_card_no>".$user_card_no."</user_card_no><user_name>".$user_name."</user_name></user><order><ssp_order_id>".$ssp_order_id."</ssp_order_id><order_no>".$order_no."</order_no><total_amount>".$total_amount."</total_amount><insurance_amount>".$insurance_amount."</insurance_amount><selfpay_amount>".$selfpay_amount."</selfpay_amount></order></inputxml></inputxml></input>";
        dump($xml);
        /* 记录请求日志   */
            $fileContent = var_export($xml, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetPreSettlement_rc/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        dump($result_list);
        $datares=$result_list['output']['order'];
        if(is_array($result_list['message'])){
            $llmessage='';  
        }else{
            $llmessage=$result_list['message']; 
        };
        if($result_list['code']=='1'){
            $returnArr['status'] = 1;
            $returnArr['errorMsg']=$llmessage;  
            $returnArr['data']['total_amount']=$datares['total_amount'];  //总费用
            $returnArr['data']['insurance_amount']=$datares['insurance_amount'];//医保支付金额
            $returnArr['data']['selfpay_amount']=$datares['selfpay_amount'];//现金支付金额
            $returnArr['data']['org_pay_amount']=$datares['org_pay_amount']; //医疗统筹支付金额        
            $returnArr['data']['grzhpay_amount']=$datares['grzhpay_amount'];//个人账户支付金额
            $returnArr['data']['settlement_datetime']=$datares['settlement_datetime'];//
        }else{//格式化为标准接口模式
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $llmessage;
        };

        /* 记录请求日志   */
            $fileContent = var_export(json_encode($returnArr), true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetPreSettlement_Re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        //dump($result_list);//die();
        //$response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        //$response = json_encode($response);
        echo json_encode($returnArr);die();  
    }

    /**
     * 医保结算
     * @param 
     */
    function GetSettlement(){
        $tcylkey = C('TCYL_KEY');
        $hospital_org_id='525009'; //医院编码
        $channel_id='1';      //渠道号 1 微信 2 支付宝 3.银联
        $user_id=$tcylkey.'ohNH9spztdajN8bGok-hJjcfrZAk';      //第三方ID
        $social_card_no='D1516917X';  //社保卡号
        $user_card_no='510402198308010012'; //身份证
        $user_name='李建辉';                //姓名
        $ssp_order_id='TC2017122203';       //平台id
        $pay_time='2017-12-22 16:08:12';    //结算时间
        $order_no='gh|178632';    //医院订单号
        $total_amount='15.00';      //总交易金额
        $insurance_amount='15';     //医保支付金额(包括医保个帐)
        $selfpay_amount='0';        //现金支付金额 

        /*$hospital_org_id  = $_POST['hospital_org_id'];    //医院编码
        $channel_id  = $_POST['channel_id'];    //渠道号 1 微信 2 支付宝 3.银联
        $user_id  = $tcylkey.$_POST['user_id'];      //第三方ID
        $social_card_no  = $_POST['social_card_no'];    //社保卡号
        $user_card_no  = $_POST['user_card_no'];    //身份证
        $user_name  = $_POST['user_name'];          //姓名
        $ssp_order_id  = $_POST['ssp_order_id'];    //平台id
        $pay_time  = $_POST['pay_time'];            //结算时间
        $order_no  = $_POST['order_no'];            //医院订单号
        $total_amount  = $_POST['total_amount'];    //总交易金额
        $insurance_amount  = $_POST['insurance_amount'];    //医保支付金额(包括医保个帐)
        $selfpay_amount  = $_POST['selfpay_amount'];    //现金支付金额*/

        $funNo='HIS017';    //交易编号
        //dump(C('URL_API'));die();
        $xml="<input><inputxml><inputxml><hospital_org_id>".$hospital_org_id."</hospital_org_id><channel_id>".$channel_id."</channel_id><user><user_id>".$user_id."</user_id><social_card_no>".$social_card_no."</social_card_no><user_card_no>".$user_card_no."</user_card_no><user_name>".$user_name."</user_name></user><order><ssp_order_id>".$ssp_order_id."</ssp_order_id><pay_time>".$pay_time."</pay_time><order_no>".$order_no."</order_no><total_amount>".$total_amount."</total_amount><insurance_amount>".$insurance_amount."</insurance_amount><selfpay_amount>".$selfpay_amount."</selfpay_amount></order></inputxml></inputxml></input>";
        /* 记录请求日志   */
            $fileContent = var_export($xml, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetSettlement_rc/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        dump($result_list);
        /* 记录请求日志   */
            $fileContent = var_export($result_list, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetSettlement_Re1/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);

        $datares=$result_list['output']['order'];
        if(is_array($result_list['message'])){
            $llmessage='';  
        }else{
            $llmessage=$result_list['message']; 
        };
        if($result_list['code']=='1'){
            $returnArr['status'] = 1;
            $returnArr['errorMsg']=$llmessage;  
            $returnArr['data']['total_amount']=$datares['total_amount'];  //总费用
            $returnArr['data']['insurance_amount']=$datares['insurance_amount'];//医保支付金额
            $returnArr['data']['selfpay_amount']=$datares['selfpay_amount'];//现金支付金额
            $returnArr['data']['org_pay_amount']=$datares['org_pay_amount']; //医疗统筹支付金额        
            $returnArr['data']['grzhpay_amount']=$datares['grzhpay_amount'];//个人账户支付金额
            $returnArr['data']['treatment_record_id']=$datares['treatment_record_id'];//医保就诊序号
            $returnArr['data']['settlement_datetime']=$datares['settlement_datetime'];//
        }else{//格式化为标准接口模式
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $llmessage;
        };

        /* 记录请求日志   */
            $fileContent = var_export(json_encode($returnArr), true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetSettlement_Re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        //dump($result_list);//die();
        /*$response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        $response = json_encode($response);*/
        echo json_encode($returnArr);die();  
    }

    /**
     * 单笔结算查询
     * @param 
     */
    function GetSettlementInquiry(){
        $tcylkey = C('TCYL_KEY');
        $user_id=$tcylkey.'ohNH9spztdajN8bGok-hJjcfrZAk';      //第三方ID
        $ssp_order_id='TC2017122203';       //平台id

        /*$user_id  = $tcylkey.$_POST['user_id'];    //第三方ID
        $ssp_order_id  = $_POST['ssp_order_id'];    //平台id*/
        
        $funNo='HIS018';    //交易编号
        //dump(C('URL_API'));die();
        $xml="<input><user_id>".$user_id."</user_id><ssp_order_id>".$ssp_order_id."</ssp_order_id></input>";
        dump($xml);
        /* 记录请求日志   */
            $fileContent = var_export($xml, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetSettlementInquiry_rc/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        dump($result_list);
        $datares=$result_list['output']['resultset']['row'];
        if(is_array($result_list['message'])){
            $llmessage='';  
        }else{
            $llmessage=$result_list['message']; 
        };
        if($result_list['code']=='1'){
            $returnArr['status'] = 1;
            $returnArr['errorMsg']=$llmessage;  
            $returnArr['data']['total_amount']=$datares['total_amount'];  //总费用
            $returnArr['data']['insurance_amount']=$datares['insurance_amount'];//医保支付金额
            $returnArr['data']['selfpay_amount']=$datares['selfpay_amount'];//现金支付金额
            $returnArr['data']['org_pay_amount']=$datares['org_pay_amount']; //医疗统筹支付金额        
            $returnArr['data']['grzhpay_amount']=$datares['grzhpay_amount'];//个人账户支付金额
            $returnArr['data']['settlement_datetime']=$datares['settlement_datetime'];//结算日期
            $returnArr['data']['treatment_record_id']=$datares['treatment_record_id'];//医保就诊序号
            $returnArr['data']['cannelpay']=$datares['cannelpay'];//支付结算状态
        }else{//格式化为标准接口模式
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $llmessage;
        };

        /* 记录请求日志   */
            $fileContent = var_export(json_encode($returnArr), true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetSettlementInquiry_Re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        //dump($result_list);//die();
        /*$response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        $response = json_encode($response);*/
        echo json_encode($returnArr);die();
    }

    /**
     * 取消结算
     * @param 
     */
    function GetCancelSettlement(){
        $tcylkey = C('TCYL_KEY');
        //$hospital_org_id='525009'; //医院编码
        $channel_id='1';      //渠道号 1 微信 2 支付宝 3.银联
        $user_id=$tcylkey.'ohNH9spztdajN8bGok-hJjcfrZAk';      //第三方ID
        $social_card_no='D1516917X';  //社保卡号
        $user_card_no='510402198308010012'; //身份证
        $user_name='李建辉';                //姓名
        $ssp_order_id='TC2017122203';       //平台id
        $order_no='gh|178632';    //医院订单号
        $treatment_record_id='100000031052621';     //医保就诊序号    医保唯一对账使用
        $total_amount='15.00';      //总交易金额
        $insurance_amount='15';
        $selfpay_amount='0';
        $cancel_datetime='2017-12-22 16:20:22';
        $funNo='HIS019';    //交易编号
        //dump(C('URL_API'));die();
        $xml="<input><inputxml><inputxml><channel_id>".$channel_id."</channel_id><user><user_id>".$user_id."</user_id><social_card_no>".$social_card_no."</social_card_no><user_card_no>".$user_card_no."</user_card_no><user_name>".$user_name."</user_name></user><order><ssp_order_id>".$ssp_order_id."</ssp_order_id><order_no>".$order_no."</order_no><treatment_record_id>".$treatment_record_id."</treatment_record_id><total_amount>".$total_amount."</total_amount><insurance_amount>".$insurance_amount."</insurance_amount><selfpay_amount>".$selfpay_amount."</selfpay_amount><cancel_datetime>".$cancel_datetime."</cancel_datetime></order></inputxml></inputxml></input>";
        /* 记录请求日志   */
            $fileContent = var_export($xml, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetCancelSettlement_rc/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        dump($xml);
        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        dump($result_list);
        /* 记录请求日志   */
            $fileContent = var_export($result_list, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetCancelSettlement_Re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        //dump($result_list);//die();
        $response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        $response = json_encode($response);
        echo $response;die();
    }

    /********************php验证身份证号码是否正确函数*********************/
    function is_idcard($id) 
    { 
        $id = strtoupper($id); 
        $regx = "/(^\d{15}$)|(^\d{17}([0-9]|X)$)/"; 
        $arr_split = array(); 
        if(!preg_match($regx, $id)) 
        { 
            return FALSE; 
        } 
        if(15==strlen($id)) //检查15位 
        { 
            $regx = "/^(\d{6})+(\d{2})+(\d{2})+(\d{2})+(\d{3})$/";      
            @preg_match($regx, $id, $arr_split); 
            //检查生日日期是否正确 
            $dtm_birth = "19".$arr_split[2] . '/' . $arr_split[3]. '/' .$arr_split[4]; 
            if(!strtotime($dtm_birth)) 
            { 
                return FALSE; 
            } else { 
                return TRUE; 
            } 
        } 
        else      //检查18位 
        { 
            $regx = "/^(\d{6})+(\d{4})+(\d{2})+(\d{2})+(\d{3})([0-9]|X)$/"; 
            @preg_match($regx, $id, $arr_split); 
            $dtm_birth = $arr_split[2] . '/' . $arr_split[3]. '/' .$arr_split[4]; 
            if(!strtotime($dtm_birth)) //检查生日日期是否正确 
            { 
                return FALSE; 
            } 
            else
            { 
                //检验18位身份证的校验码是否正确。 
                //校验位按照ISO 7064:1983.MOD 11-2的规定生成，X可以认为是数字10。 
                $arr_int = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); 
                $arr_ch = array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'); 
                $sign = 0; 
                for($i = 0; $i < 17; $i++ ) 
                { 
                    $b = (int) $id{$i}; 
                    $w = $arr_int[$i]; 
                    $sign += $b * $w; 
                } 
                $n = $sign % 11; 
                $val_num = $arr_ch[$n]; 
                if($val_num != substr($id,17, 1)) 
                { 
                    return FALSE; 
                } //phpfensi.com 
                else
                { 
                    return TRUE; 
                } 
            } 
        } 
      
    } 

}
?>